﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace TreeBuilder
{
	public class MoveNodeAction : UndoableAction
	{
		private readonly INode _node;
		private readonly Point _destination;
		private Point? _oldPosition;

		public MoveNodeAction(INode node, Point destination, Point? oldPosition = null)
		{
			_node = node;
			_destination = destination;
			_oldPosition = oldPosition;
		}

		public override void Execute()
		{
			MoveNode(_destination);
		}

		public override void Undo()
		{
			if (!_oldPosition.HasValue)
				throw new InvalidOperationException("No point to move the node");
			MoveNode(_oldPosition.Value);
		}

		private void MoveNode(Point pos)
		{
			_node.TopCenter = pos;
		}
	}
}
